#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <iostream>
#include "myOpenCVLIB\myheader.h"


using namespace std;  
using namespace cv; 


int main(){

	const double alpha = 2;
	const int beta = 50;

	Mat image = imread(MOTOR_1366x768);
	if(!image.data){
		cout << "cannot load image";
		getchar();
		return -1;
	}

	Mat changed = Mat::zeros(image.size(), image.type());


	

	double t = (double)getTickCount();

	//iterate by pixels avg time 1.12s
	/*for(int row=0; row < image.rows;row++){
		for(int col=0; col < image.cols;col++){
			for(int ch = 0;ch < 3 ;ch++){
				changed.at<Vec3b>(row,col)[ch] = saturate_cast<uchar>(alpha * image.at<Vec3b>(row,col)[ch] + beta);
			}
		}
	}*/


	//iterate by col pointer avg time 0.27
	const int columns = image.cols * image.channels();
	for(int row=0; row < image.rows;row++){
		uchar *outRow = changed.ptr<uchar>(row);
		uchar *inRow = image.ptr<uchar>(row);

		for(int col=0; col < columns ;col++){
			*outRow++ = saturate_cast<uchar>(alpha * inRow[col] + beta);
		}
	}

	t = ((double)getTickCount() - t) / getTickFrequency();
	cout << "time: " << t;

	namedWindow("image");
	imshow("image" ,image);

	namedWindow("changed");
	imshow("changed" ,changed);

	waitKey(0);

	return 0;
}